Page({
    data: {
        more_list: !1,
        _num: 1,
        keyword: "",
        page: 1,
        id: null,
        status: null,
        page_loading: !0,
        list: [],
        is_switch: !1,
        is_delete: !1,
        toSearch: !1,
        device: null,
        actions: [ {
            name: "取消",
            color: "#666666"
        }, {
            name: "确认",
            color: "#446dfd",
            loading: !1
        } ]
    },
    onLoad: function(t) {
        getApp().device().indexOf("iphone_x") > -1 && this.setData({
            iphone_x: !0
        }), this.getList();
    },
    search: function() {
        this.getList();
    },
    toEdit: function(t) {
      var a = t.currentTarget.dataset.id;
      getApp().core.navigateTo({
        url: '/app_admin/add-goods/add-goods?id=' + a
      });
      // this.setData({
      //     id: a,
      //     is_delete: !0
      // });
    },
    toSwitch: function(t) {
        var a = t.currentTarget.dataset.id, e = t.currentTarget.dataset.status;
        this.setData({
            id: a,
            status: e,
            is_switch: !0
        });
    },
    toDelete: function(t) {
        var a = t.currentTarget.dataset.id;
        this.setData({
            id: a,
            is_delete: !0
        });
    },
    cancel: function() {
        this.setData({
            is_delete: !1,
            is_switch: !1
        });
    },
    goods_destroy: function() {
      var t = this;
      getApp().core.showLoading()
      getApp().request({
        url: getApp().api.admin.goods.goods_del,
        data: {
          id: this.data.id
        },
        method: "post",
        success: function (a) {
          getApp().core.hideLoading(), 0 == a.code ? (t.getList(1), t.setData({
            is_delete: !1
          })) : getApp().core.showToast({
            title: a.msg,
            icon: 'none'
          });
        },
        fali: function (t) {
          getApp().core.hideLoading()
          getApp().core.showToast({
            title: t.msg,
            icon: 'none'
          })
        }
      });
    },
    goods_switch: function() {
        var t = this;
       getApp().core.showLoading()
        getApp().request({
            url: getApp().api.admin.goods.goods_switch,
            data: {
                status: this.data.status,
                id: this.data.id
            },
            method: "post",
            success: function(a) {
              getApp().core.hideLoading(), 0 == a.code ? (t.getList(1), t.setData({
                is_switch: !1
              })) : getApp().core.showToast({
                title: a.msg,
                icon: 'none'
              });
            },
            fali: function(t) {
              getApp().core.hideLoading()
              getApp().core.showToast({
                title: t.msg,
                icon: 'none'
              })
            }
        });
    },
    tab: function(t) {
        var a = t.currentTarget.dataset.num;
        this.setData({
            _num: a,
            keyword: "",
            list: []
        }), this.getList();
    },
    reset: function() {
        this.setData({
            id: null
        });
    },
    onclick: function(t) {
        var a = t.currentTarget.dataset.id;
        this.setData({
            id: a
        });
    },
    beSearch: function() {
        var t = !this.data.toSearch;
        this.data.keyword.length > 0 && (t = this.data.toSearch), this.setData({
            toSearch: t
        });
    },
    input: function(t) {
        this.setData({
            keyword: t.detail.value
        });
    },
    getList: function() {
        var t = this;
        getApp().core.showLoading(), getApp().request({
            url: getApp().api.admin.goods.list,
            data: {
                page: 1,
                keyword: this.data.keyword,
                status: this.data._num
            },
            method: "get",
            success: function (a) {
              getApp().core.hideLoading()
              if ( 0 == a.code) {
                var e = a.data.list, i = !1;
                20 == e.length && (i = !0), t.setData({
                  list: e,
                  more_list: i,
                  page: 2,
                  id: null
                });
              } else getApp().core.showToast({
                title: a.msg,
                icon:'none'
              });
            },
            fali:function (t) {
              getApp().core.hideLoading()
              getApp().core.showToast({
                content: t.msg,
                icon: 'none'
              });
            }
        });
    },
    getMore: function() {
        var t = this, a = this.data.page;
        getApp().core.showLoading({
        }), getApp().request({
            url: getApp().api.admin.goods.list,
            data: {
                page: a,
                keyword: this.data.keyword,
                status: this.data._num
            },
            method: "get",
            success: function (e) {
              getApp().core.hideLoading()
              if ( 0 == e.code) {
                var i = t.data.list, s = e.data.list, n = !1;
                20 == s.length && (n = !0), i = i.concat(s), a++ , t.setData({
                  list: i,
                  page: a,
                  more_list: n,
                  id: null
                });
              } else getApp().core.showToast({
                title: e.msg,
                icon: 'none'
              });
            },
            fali: function (t) {
              getApp().core.hideLoading()
              getApp().core.showToast({
                content: t.msg,
                icon: 'none'
              });
            }
        });
    },
    onReady: function(t) {
        this.setData({
            page_loading: !1
        });
    },
    onShow: function() {
        var t = this;
        getApp().core.getStorage({
            key: "goods_status",
            success: function(a) {
                "保存成功" == a.data ? (t.setData({
                    _num: 1
                }), t.getList(), getApp().core.removeStorage({
                    key: "goods_status",
                    success: function(t) {}
                })) : t.getList();
            },
            fail: function(a) {
                t.getList();
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.more_list && this.getMore(this.data.page);
    },
    onShareAppMessage: function() {}
});